package com.my.strings.reg;

import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * @description:
 * @author: marshal
 * @date: 2021-08-04 3:26 PM
 */
public class RegTest {
    public static void main(String[] args) {
        System.out.println(isNum("agagb"));
        System.out.println(isNum("12.98"));
        System.out.println(isIp("192.167.8.9"));
        System.out.println(isIp("12141515"));
    }

    /**
     *  校验数字
     *
     * @param str
     * @return
     */
    private static boolean isNum(String str) {
        String numReg = "^-?\\d+(\\.\\d+)?$";
        return str.matches(numReg);
    }

    /**
     *  校验IP
     *
     * @param str
     * @return
     */
    private static boolean isIp(String str) {
        String ipReg = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
        return str.matches(ipReg);
    }

}
